package com.ppsea;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class OldFxwrTool
{
  public static void main(String[] args)
  {
    Display display = new Display();
    Shell shell = new Shell(display, 1168);
    shell.setSize(600, 300);
    shell.setText("Old非仙勿扰管理工具");
    shell.setLayout(new FillLayout());

    Composite composite = new Composite(shell, 0);
    composite.setLayout(new GridLayout(4, false));

    final Combo cmbType = new Combo(composite, 2056);
    cmbType.add("QQ");
    cmbType.add("UID");
    cmbType.setData("QQ", Integer.valueOf(1));
    cmbType.setData("UID", Integer.valueOf(2));
    cmbType.select(0);
    GridData typeGrid = new GridData(16384, 128, false, false);
    typeGrid.widthHint = 30;
    cmbType.setLayoutData(typeGrid);

    final Text txtQQ = new Text(composite, 2048);
    GridData qqGrid = new GridData(4, 128, true, false);
    qqGrid.widthHint = 150;
    txtQQ.setLayoutData(qqGrid);
    txtQQ.setFocus();

    final Combo cmbZone = new Combo(composite, 2056);
    cmbZone.add("仙界");
    cmbZone.add("魔界");
    cmbZone.setData("仙界", Integer.valueOf(1));
    cmbZone.setData("魔界", Integer.valueOf(2));
    cmbZone.select(0);
    GridData zoneGrid = new GridData(16384, 128, false, false);
    zoneGrid.widthHint = 50;
    cmbZone.setLayoutData(zoneGrid);

    Button btnGenerateBookMark = new Button(composite, 0);
    btnGenerateBookMark.setText("生成书签");
    btnGenerateBookMark.setLayoutData(new GridData(4, 128, false, false));

    final Text txtResult = new Text(composite, 2818);
    GridData resultGrid = new GridData(4, 4, true, true, 4, 1);
    txtResult.setLayoutData(resultGrid);

    btnGenerateBookMark.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        try {
          int type = Integer.valueOf(cmbType.getData(cmbType.getText()).toString()).intValue();
          String uid = txtQQ.getText();
          if (type == 1)
          {
            uid = Utils.QQ2Uid(txtQQ.getText());
          }
          int zone = Integer.valueOf(cmbZone.getData(cmbZone.getText()).toString()).intValue();
          String pwd = Utils.queryPlayerPwd(uid, zone);

          int hashcode = Math.abs(uid.hashCode());
          StringBuilder content = new StringBuilder();
          content.append(Utils.generateFxwrBookMark(uid, pwd, zone)).append("\r\n\r\n\r\n");
          content.append("仙界app:").append(hashcode % 12).append("\r\n");
          content.append("仙界data:").append(hashcode % 9).append("\r\n");
          content.append("仙界profile:").append(hashcode % 4).append("\r\n\r\n");

          content.append("魔界app:").append(hashcode % 8).append("\r\n");
          content.append("魔界data:").append(hashcode % 3).append("\r\n");
          content.append("魔界profile:").append(hashcode % 2).append("\r\n\r\n");

          content.append("database:").append(hashcode % 10).append("\r\n");
          content.append("item database:").append(hashcode % 50);
          txtResult.setText(content.toString());
        }
        catch (Exception ex) {
          txtResult.setText(ex.getMessage());
        }
      }
    });
    SWTUtils.centerWnd(shell);

    shell.open();

    while (!shell.isDisposed())
      if (!display.readAndDispatch())
        display.sleep();
  }
}